home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 544b.lha / 4D Navigator / startup.asm < prev    next >
Assembly Source File  |  1991-09-06  |  3KB  |  119 lines

  1. *** Startup module for the 4D Navigator program
  2. *   See 4d.c for copyright notice
  3.  
  4.     include "libraries/dosextens.i"
  5.     include "workbench/startup.i"
  6.  
  7.     public    _LVOOldOpenLibrary
  8.     public    _LVOFindTask,_LVOWaitPort,_LVOGetMsg
  9.     public    _LVOCurrentDir
  10.     public    _LVOForbid,_LVOReplyMsg
  11.  
  12. AbsExecBase    equ    4
  13.  
  14.     entry    .begin
  15.     public    .begin
  16. .begin
  17.     far    data
  18.     lea    __H1_org+32766,a4    ; geta4
  19.     near    data
  20.  
  21.     ; Determine if INITALIZED and UNINITIALIZED data segments are together
  22.     lea    __H1_end,a1
  23.     lea    __H2_org,a2
  24.     cmp.l    a1,a2
  25.     ; If so, skip the operation as data will already be set to zero
  26.     bne    2$
  27.  
  28.     ; Determine amount of memory to clear
  29.     move.w    #((__H2_end-__H2_org)/4)-1,d1
  30.     ; Skip if no UNINITIALIZED data
  31.     bmi    2$
  32.  
  33.     ; "Clear global variables" loop
  34. 1$    clr.l    (a1)+
  35.     dbra    d1,1$
  36.  
  37. 2$    ; Set up the EXEC library base pointer
  38.     movea.l AbsExecBase,a6
  39.     move.l    a6,_SysBase
  40.  
  41.     ; Get our task address
  42.     suba.l    a1,a1
  43.     jsr    _LVOFindTask(a6)
  44.     move.l    d0,_ThisProc
  45.  
  46.     ; Get and save the WB startup message, if not started from CLI
  47.     move.l    d0,a5
  48.     moveq    #0,d0
  49.     tst.l    pr_CLI(a5)
  50.     bne    3$
  51.     lea    pr_MsgPort(a5),a0
  52.     jsr    _LVOWaitPort(a6)
  53.     lea    pr_MsgPort(a5),a0
  54.     jsr    _LVOGetMsg(a6)
  55. 3$    move.l    d0,_WBenchMsg
  56.  
  57.     ; Open DOS library
  58.     ;  1.  Any version
  59.     ;  2.  Assumes success!!!
  60.     ;  3.  Not closed on exit!
  61.     lea    dos_name,a1
  62.     jsr    _LVOOldOpenLibrary(a6)
  63.     move.l    d0,_DOSBase
  64.  
  65.     ; Set current directory on WB startup
  66.     move.l    _WBenchMsg,d0
  67.     beq    4$
  68.     move.l    d0,a0
  69.     move.l    sm_ArgList(a0),a0
  70.     move.l    wa_Lock(a0),d1
  71.     move.l    _DOSBase,a6
  72.     jsr    _LVOCurrentDir(a6)
  73.  
  74.     public    _main
  75. 4$    jmp    _main        ; must return via exit()
  76.  
  77.  
  78.     public    _exit,__exit
  79. _exit
  80. __exit
  81.     move.l    4(sp),d0        ; fetch exit() return code
  82. exit
  83. * A static initial SP variable is not used in this code.  We are using the
  84. * fact that AmigaDOS places the address of the top of our stack in SP and
  85. * proc->pr_ReturnAddr right before JSR'ing to us.  This code uses
  86. * pr_ReturnAddr when restoring SP.
  87.     move.l    _ThisProc,a5
  88.     move.l    pr_ReturnAddr(a5),sp
  89.     subq.l    #4,sp        ; subtract 4 for return address
  90.  
  91.     ; Return the WB startup message, if applicable
  92.     tst.l    _WBenchMsg
  93.     beq.s    1$
  94.     ;  We Forbid() so Workbench can't UnLoadSeg() us before we're done
  95.     move.l    d0,-(sp)        ; put return code temporarily on stack
  96.     move.l    _SysBase,a6
  97.     jsr    _LVOForbid(a6)
  98.     move.l    _WBenchMsg,a1
  99.     jsr    _LVOReplyMsg(a6)
  100.     move.l    (sp)+,d0        ; pull return code off stack and return to DOS
  101.  
  102. 1$    rts
  103.  
  104.  
  105. dos_name    dc.b    'dos.library'      ,0
  106.  
  107.     dseg
  108.  
  109.     ; Data segment labels (used above)
  110.     public    __H1_org,__H1_end,__H2_org,__H2_end
  111.  
  112.     ; Global variables set up by this startup code
  113.     global _SysBase,4
  114.     global _DOSBase,4
  115.     global _WBenchMsg,4
  116.     global _ThisProc,4
  117.  
  118.     end
  119.